Skip to content

feat(lsp): auto-enable WordPress stubs for WordPress projects#17236

Open
superdav42 wants to merge 2 commits intoanomalyco:devfrom
superdav42:feature/wordpress-lsp-auto-config-v2
Open

feat(lsp): auto-enable WordPress stubs for WordPress projects#17236
superdav42 wants to merge 2 commits intoanomalyco:devfrom
superdav42:feature/wordpress-lsp-auto-config-v2

Conversation

@superdav42
Copy link

@superdav42 superdav42 commented Mar 12, 2026

Issue for this PR

Closes #5574

Type of change

  • New feature

What does this PR do?

When using LSP in OpenCode, the built-in PHP Intelephense flags WordPress native functions as undefined (add_action, add_filter, etc.), which blocks agent edits.

This PR adds automatic detection of WordPress projects and enables WordPress stubs for Intelephense. Detection works for:

  1. WordPress core installations (wp-config.php, wp-content/, etc.)
  2. WordPress plugins (Plugin Name: header in PHP files)
  3. WordPress themes (Theme Name: header in PHP files)
  4. WordPress code patterns (add_action, add_filter function calls)

When WordPress is detected, the LSP is automatically configured with intelephense.stubs: ["wordpress"].

How did you verify your code works?

  1. The detection logic checks for WordPress files/patterns in the project root
  2. Tested with a WordPress plugin project - functions are now recognized
  3. Uses existing pathExists helper and fs.readdir patterns already in the codebase
  4. Limits file reading to 10 PHP files for performance

Screenshots / recordings

N/A - This is an LSP configuration change, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 12, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Automatically detect WordPress projects including:
- WordPress core installations (wp-config.php, wp-content/, etc.)
- WordPress plugins (Plugin Name: header)
- WordPress themes (Theme Name: header)
- WordPress code patterns (add_action, add_filter, etc.)

When detected, automatically enables intelephense.stubs with 'wordpress'
for proper function completions and hover information.

Fixes anomalyco#5574

See: bmewburn/vscode-intelephense#1302
@superdav42 superdav42 force-pushed the feature/wordpress-lsp-auto-config-v2 branch from c23ade0 to 549315c Compare March 12, 2026 20:02
- Simplify detection: use filesystem markers only (no PHP content scanning)
  - Core: wp-config.php, wp-settings.php, wp-load.php
  - Plugin: main PHP file with 'Plugin Name:' header
  - Theme: style.css with 'Theme Name:' header
  - Composer: wordpress/*, wpackagist-*, johnpbloch/wordpress, roots/wordpress
  - Parent dirs: detect WP core 2-3 levels up (plugins/themes inside wp-content)

- Fix stubs: include full Intelephense default stubs list alongside 'wordpress'
  (setting stubs replaces defaults, so ['wordpress'] alone removes Core, SPL, etc.)

- Add diagnostics.undefinedTypes: false to suppress false positives for types
  from other plugins/packages not covered by stubs (free tier limitation)

- Add environment.includePaths pointing to WP core when detected, so
  Intelephense can resolve WP core classes and functions directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Support PHP Intelephense Stubs

1 participant